package com.thesis.client;

import android.app.ActionBar;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.TextView;

import com.thesis.conectify.Connectify;
import com.thesis.object.ListBillDescription;
import com.thesis.utils.Defines;

public class BillDetailStatictisActivity extends Activity {
	ListView list_bill_detail;
	TextView totalcost;
	TextView bill_time;
	String[] bill_id;
	ListBillDescription listBill;
	ListBillDescription listresult;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_bill_detail_statistic);
		
		bill_id = getIntent().getStringArrayExtra(Defines.BILL_DETAIL);
		ActionBar ab = getActionBar();
		//ab.setTitle(getResources().getString(R.string.title_activity_statistic));
		
		ab.setDisplayHomeAsUpEnabled(true);
		list_bill_detail = (ListView) findViewById(R.id.list_item_bill_detail);
		totalcost = (TextView) findViewById(R.id.bds_tv_totalcost);
		bill_time = (TextView) findViewById(R.id.bds_tv_time);
		new ViewBillDetail().execute();
	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.bill_detail, menu);
//		return true;
//	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
	public class ViewBillDetail extends AsyncTask<String, String, String>{

		@Override
		protected String doInBackground(String... params) {
			Connectify connect = new Connectify(BillDetailStatictisActivity.this);
			
			listBill = connect.getListBillDescription(bill_id[1].substring(0, 10), bill_id[1].substring(0, 10));
			
			return null;
		}
		
		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			
			listresult = new ListBillDescription();
			for (int i = 0 ; i < listBill.getListBill().size();i++){
				if (listBill.getListBill().get(i).getBillId() == Integer.parseInt(bill_id[0])){
					listresult.getListBill().add(listBill.getListBill().get(i));
				}
			}
			
			list_bill_detail.setAdapter(new BillDetailStatictisAdapter(BillDetailStatictisActivity.this, listresult));
			totalcost.setText(bill_id[2]+"đ");
		}
	}
}
